package e

import (
	"fmt"
	"net/http"

	"github.com/gin-gonic/gin"
)

type Response struct {
	Code int         `json:"code"`
	Data interface{} `json:"data"`
	Msg  string      `json:"msg"`
}

type ResponseList struct {
	Success  bool        `json:"success"`
	Data     interface{} `json:"data"`
	Msg      string      `json:"msg"`
	Page     int         `json:"page"`
	PageSize int         `json:"pageSize"`
	Total    int64       `json:"total"`
}

func ListSuccess(data interface{}, msg string, current, pageSize int, total int64, c *gin.Context) {

	fmt.Println("list Success", data, total)
	c.JSON(http.StatusOK, ResponseList{
		true,
		data,
		msg,
		current,
		pageSize,
		total,
	})
}
func Success(data interface{}, msg string, c *gin.Context) {
	c.JSON(http.StatusOK, Response{
		SUCCESS,
		data,
		msg,
	})
}

func Fail(code int, data interface{}, msg string, c *gin.Context) {
	m := ""
	if msg != "" {
		m = msg
	} else if GetMSG(code) != "" {
		m = GetMSG(code)
	}
	c.JSON(http.StatusInternalServerError, Response{
		code,
		data,
		m,
	})
}
